<?php

namespace App\Http\Admin\Controller;

use App\Http\Admin\CurrentUser;
use App\Http\Admin\Middleware\AuthMiddleware;
use App\Http\Common\Controller\AbstractController;
use App\Http\Common\Result;
use App\Http\Request\AuthorizeRequest;
use App\Request\auth\AdminRequest;
use App\Request\auth\Service\Auth\AdminService;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\Validation\Annotation\Scene;


#[Controller]
class PublicController extends AbstractController
{

    public function __construct(
        protected readonly AdminService  $adminService,
        protected readonly CurrentUser $currentUser

    )
    {
    }

    #[Scene(scene: 'authorize',argument: 'request')]
    #[PostMapping('/adminapi/authorize')]
    public function authorize(AdminRequest $request): Result
    {
        return $this->success($this->adminService->login($request->input('account'), $request->input('password')));
    }

    #[GetMapping('/adminapi/index')]
    #[Middlewares([
        AuthMiddleware::class,
    ])]
    public function index(): Result
    {
//        return  $this->success();
        return $this->success($this->currentUser->getUser());
    }


}